package cn.itcast.controller;

import cn.itcast.domain.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class StandardController {

    @Autowired
    private StandardService standardService;

    @RequestMapping("/standard_save")
    public String save(Standard standard){
        standardService.save(standard);
        return "redirect:/pages/base/standard.html";
    }


    /**
     * 分页
     * @return
     */
    @RequestMapping("/standard_pageQuery")
    @ResponseBody
    public Map pageQuery(int page,int rows){

        //查询所有分页对象
        Page<Standard> standards = standardService.findPage(page, rows);

        Map<String,Object> result = new HashMap<String,Object>();

        result.put("total",standards.getTotalElements());
        result.put("rows", standards.getContent());

        return result;

    }
}
